<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>原型对象</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    
    <script type="text/javascript">
        /* 
        原型对象的所有属性会被实例使用，且所有实例共享

        实例只能使用原型属性，不能设置原型属性
        */

        function User(name){
            this.name = name;
        }

        User.prototype.friends = [];
        User.prototype.age = 24;
        User.prototype.sayName = function (){
            console.log(this.name);
        };

        var libai = new User("李白");
        var sushi = new User("苏轼");

        console.log(libai, sushi);

        sushi.friends = ["王安石"];

        // sushi.friends.push("王安石");

        console.log("libai.friends", libai.friends);

        sushi.sayName();

        // 实例只能读取原型属性，但是不能设置原型属性
        console.log("libai.age",libai.age); // 24
        libai.age = 35;
        console.log("sushi.age", sushi.age); // 24
    </script>
</body>
</html>